package com.yyfax.pay.quartz.fixed;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

/**
 * 系统数据字典初始化
 * 
 * @author maojian
 * @date 2017-08-05 18:06:42
 * @since v1.0.0
 */
public class InitializerListener implements ApplicationListener<ContextRefreshedEvent> {

	private Logger logger = LoggerFactory.getLogger(getClass());

	private boolean isInit;
	
	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
		if (!isInit && event.getApplicationContext().getParent() == null) {
			Map<String, QuartzConfigure> configures = QuartzConfigure.configures;
			for(String configKey : configures.keySet()){
				QuartzConfigure config = configures.get(configKey);
				QuartzTaskUtils.createJob(config.getCronEx(), config.getName(),
						config.getJobClass(), true);
			}
			isInit = true;
		}

	}

}
